import sys
import os
sys.path.append("..")

from CoreSim.Unit import *
from CoreSim.Simulator import *
from CoreSim.SchedulerDelay import *
from CoreSim.SchedulerIdeal import *

if __name__ == "__main__":
    
    numHosts = 10
    numLinks = 10
    numSwitches = 16
    link_sh_Bw = 10.0 * Gb
    link_ss_Bw = 10.0 * Gb

    load = 0.8
    randomSeed = 1
    FLOW_LAUNCH_END_TIME = 0.05
    trafficType = 'CDF'
    cdfId = 1
    cdf_type = ['DCTCP', 'VL2']
    cdfFileName = "cdf/%s_CDF.txt"%cdf_type[cdfId]
    flowsFileName = "%s_%sToRs_%sHosts_%sLinks_%sLoad_%sTime.txt"\
                    %(cdf_type[cdfId], numSwitches, numHosts, numLinks, load, FLOW_LAUNCH_END_TIME)
    
    
    compile_cmd = "g++ ./Input/fct.cc -o ./Input/fct -std=c++11"
    os.system(compile_cmd)
    
    if not os.path.isfile(inDir+flowsFileName):
        print '!!!!'
        run_cmd = "./Input/fct numHosts " + str(numHosts) + " numLinks " + str(numLinks) \
            + " numSwitches " + str(numSwitches) + " link_sh_Bw " + str(link_sh_Bw) \
            + " link_ss_Bw " + str(link_ss_Bw) + " load " + str(load) + " randomSeed " \
            + str(randomSeed) + " cdfFileName " + inDir + cdfFileName + " flowsFileName " \
            + inDir + flowsFileName + " FLOW_LAUNCH_END_TIME " + str(FLOW_LAUNCH_END_TIME) 
        os.system(run_cmd)
    
    sim = Simulator()
    sim.AssignSdnScheduler(Scheduler=SchedulerDelay(numHosts, numSwitches, numLinks, 10.0 * Gb), args=(trafficType, flowsFileName))
    #sim.AssignSdnScheduler(Scheduler=SchedulerIdeal(numHosts, numSwitches, 10.0 * Gb), args=(trafficType, flowsFileName))
    sim.Run()
    sim.sched.PrintFlows()